package com.tgpms.web.system.controller;

import com.tgpms.common.Result;
import com.tgpms.exception.ExceptionExplain;
import com.tgpms.util.Common;
import com.tgpms.web.system.entity.MenuVisitorRecord;
import com.tgpms.web.system.service.MenuVisitorRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * Created By Riven on 2020-9-23
 */
@Api(value = "MenuVisitorRecordController", tags = "访问菜单接口")
@RestController
@RequestMapping("/ev/menuVisitorRecord")
public class MenuVisitorRecordController {

    @Resource
    private MenuVisitorRecordService menuVisitorRecordService;

    @ApiOperation(value = "访问菜单接口",notes = "访问菜单接口",httpMethod = "POST")
    @PostMapping(value = "/addMenuVisitorRecord")
    public Result addMenuVisitorRecord(@RequestBody MenuVisitorRecord menuVisitorRecord) {
        Result result = new Result();
        try{
            if(Common.isEmpty(menuVisitorRecord.getMenuUrl()) || Common.isEmpty(menuVisitorRecord.getMenuName())) {
                result.setSuccess(false);
                result.setMsg(ExceptionExplain.EMPTY_BY_DATA.getExplain());
                return result;
            }
            result = menuVisitorRecordService.add(menuVisitorRecord);
        } catch (Exception e) {
            e.printStackTrace();
            result.setSuccess(false);
            result.setMsg("增加异常");
            return result;
        }
        return result;
    }
}
